package com.xyb.controller;

import com.xyb.entity.SysRole;
import com.xyb.service.RoleService;
import com.xyb.vo.SysRoleVo;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("role")
public class RoleController {

    @Resource
    private RoleService roleService;

    @GetMapping("roles")
    public List<SysRole> selectSysRoleList() {
        return roleService.selectSysRoleList();
    }

    @GetMapping("role/{roleId}")
    public SysRoleVo selectSysRoleByRoleId(@PathVariable("roleId") Long roleId) {
        return roleService.selectSysRoleByRoleId(roleId);
    }

    @PostMapping("role")
    public String insertSysRole(@RequestBody SysRoleVo sysRoleVo){
        return roleService.insertSysRole(sysRoleVo);
    }

    @PutMapping("role/{roleId}")
    public String updateSysRole(@PathVariable("roleId") Long roleId,@RequestBody @Validated(SysRoleVo.update.class) SysRoleVo sysRoleVo){
        sysRoleVo.setRoleId(roleId);
        return roleService.updateSysRole(sysRoleVo);
    }

    @PutMapping("role/order")
    public String updateSysRoleShowOrder(@RequestBody Long[] roleIds){
        return roleService.updateSysRoleShowOrder(roleIds);
    }

    @DeleteMapping("role/{roleId}")
    public String deleteSysRoleByRoleId(@PathVariable("roleId") Long roleId){
        return roleService.deleteSysRoleByRoleId(roleId);
    }
}
